import moment from 'moment';
import { Op } from 'sequelize';
import Service from '../../../core/baseService';

export default class FruitService extends Service {
  constructor(ctx) {
    super(ctx);
    this.model = ctx.sassmodel.FruitBill;
  }

  async detail(id) {
    const result = await this.model.findOne({
        where: { id },
        include: [
          {
            model: this.ctx.model.FruitBillList,
          },
        ],
    });
    return result;
  }

  async statistics(params) {
    const { date } = params;
    const billInfoList = await this.ctx.sassmodel.FruitBillList.findAll({
      where: {
        create_at: {
          [Op.gt]: moment(date[0]).startOf('day').unix(),
          [Op.lt]: moment(date[1]).endOf('day').unix()
        }
      }
    });
    const fruitList = await this.model.findAll({
      where: {
        create_at: {
          [Op.gt]: moment().startOf('day').unix(),
          [Op.lt]: moment().endOf('day').unix()
        }
      }
    })
    return {
      billInfoList,
      fruitList
    };
  }


}
